﻿@using System.Collections.Generic
@using System.Collections.ObjectModel
@using System.Web.Http.Description
@using System.Threading
@using epalpay.api.help.ModelDescriptions
@model IList<ParameterDescription>

@if (Model.Count > 0) {
    <table class="help-page-table">
        <thead>
            <tr><th>Name</th><th>Description</th><th>Type</th><th>Additional information</th></tr>
        </thead>
        <tbody>
            @foreach (ParameterDescription parameter in Model) {
                ModelDescription modelDescription = parameter.TypeDescription;
                <tr>
                    <td class="parameter-name">@parameter.Name</td>
                    <td class="parameter-documentation">
                        <p>
                            @if (parameter.Documentation != null) {
                                @Html.Raw(parameter.Documentation != null ? parameter.Documentation.Replace("\r\n", "<br/>") : "")
                            } else if (parameter.Documentation == null) {
                                if (modelDescription.Documentation != null) {
                                    @modelDescription.Documentation
                                } else {
                                    if (modelDescription.ModelType.IsGenericType) {
                                        if (modelDescription is ComplexTypeModelDescription) { 
                                            @modelDescription.Documentation
                                        } else {
                                            var eldes = ((CollectionModelDescription)modelDescription).ElementDescription;
                                            @eldes.Documentation
                                        }
                                    }
                                }
                            }
                        </p>
                    </td>
                    <td class="parameter-type">
                        @Html.DisplayFor(m => modelDescription.ModelType, "ModelDescriptionLink", new { modelDescription = modelDescription })
                    </td>
                    <td class="parameter-annotations">
                        @if (parameter.Annotations.Count > 0) {
                            foreach (var annotation in parameter.Annotations) {
                                <p>@annotation.Documentation</p>
                            }
                        } else {
                            <p>None.</p>
                        }
                    </td>
                </tr>
            }
        </tbody>
    </table>
} else {
    <p>None.</p>
}

